package com.fruit.auth.model;

import java.io.Serializable;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.DynamicUpdate;

import lombok.Data;

@Entity
@Table(name="AUTH_DEPARTMENT")
@Data
@DynamicUpdate
public class Department implements Serializable
{
	private static final long serialVersionUID = -6626399054297077120L;
	
	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	private Integer id;
	
	private String code;//机构代码
	private String name;//名称
	private String description;//描述
	private String phone;//联系电话
	
	@Transient
	private Integer pid;
	
	@ManyToOne(cascade = CascadeType.DETACH,fetch=FetchType.LAZY)
	@JoinColumn(name="pid")
	private Department parent;//上级部门
	
	@OneToOne(cascade = CascadeType.DETACH,fetch=FetchType.LAZY)
	@JoinColumn(name="AUTH_USER_id")
	private User manager;//部门主管
	
	@JoinColumn(updatable=false)
	private Boolean leaf=Boolean.TRUE;
}
